import React from 'react'
import {Button} from 'antd'
import LwjTable from 'components/LwjTable/LwjTable'
import { contractOrderType, productType, contractOrderStatus, contractActionType } from 'utils/enumConfig'
import AuditModal from './AuditModal'
import ContractDetailModal from '../../orderList/$state/ContractDetailModal'

const List = ({
                dispatch,
                visible,
                currentItem,
                contractDetailModalProps,
                ...tableProps,
              }) => {
  const onAudit = (record) => {
    dispatch({
      type: 'orderCancel/showAuditModal',
      payload: record
    })
  }
  const onDetail = (record) => {
    dispatch({
      type: 'orderList/onShowContractDetail',
      payload: {
        contractOrderId: record.contractId,
        salesOrderId: record.salesOrderId
      }
    })
  }

  const columns = [
    {
      title: '合同号',
      dataIndex: 'contractNum',
      key: 'contractNum',
      render: (text, record) => (
        <span>
        <a  onClick={() => onDetail(record)}>{record.contractNum}</a>
        <Button
          onClick={() => onDetail(record)}
          size="small"
          shape="circle"
          icon="search"
          style={{ marginLeft: 5 }} />
      </span>
      )
    }, {
      title: '门店',
      dataIndex: 'distributorName',
      key: 'distributorName'
    }, {
      title: '合同类型',
      dataIndex: 'contractOrderType',
      key: 'contractOrderType',
      render: (text, record, index) => (contractOrderType[record.contractOrderType])
    }, {
      title: '产品类型',
      dataIndex: 'productType',
      key: 'productType',
      render: (text, record, index) => (productType[record.productType])
    }, {
      title: '合同状态',
      dataIndex: 'contractOrderStatus',
      key: 'contractOrderStatus',
      render: (text, record, index) => (contractOrderStatus[text])
    }, {
      title: '取消原因',
      dataIndex: 'cancelReason',
      key: 'cancelReason',
    }, {
      title: '审核备注',
      dataIndex: 'auditRemark',
      key: 'auditRemark',
    },
    // {
    //   title: '操作',
    //   dataIndex: 'handle',
    //   key: 'handle',
    //   render: (text, record) => (
    //     <span>
    //       <a onClick={() => onDetail(record)}>查看</a>
    //     </span>
    //   )
    // }
  ]

  const auditModalProps = {
    visible,
    title: '审核取消合同',
    confirmLoading: false,
    currentItem: currentItem,
    destroyOnClose: true,
    width: 1200,
    footer: false,
    dispatch,
    onCancel: () => {
      dispatch({
        type: 'orderCancel/hideModal',
        payload: {}
      })
    }
  }


  return (
    <div>
      <LwjTable
        {...tableProps}
        dispatch={dispatch}
        columns={columns}/>
      {visible && <AuditModal {...auditModalProps}/>}
      <ContractDetailModal {...contractDetailModalProps} />
    </div>
  )
}

export default List
